﻿
///----------------------------------------------
///2012.4.30 汪定新 添加
///


if (typeof ($) != "undefined") {
    $(document).ready(function () {
        var now = new Date();
        y = now.getFullYear();
        m = now.getMonth() + 1;
        d = now.getDate();
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        var myDate = y + "-" + m + "-" + d;



        var empId = getPar1("empId");
        instance[0].EmployeeID = empId;
        instance[0].PreDeptID = parent._key; //调整前部门
        instance[0].ReportDate = myDate; //提报日期
        //获取当前部门和岗位
        var deptName = getPar1("deptName");
        var postName = getPar1("postName");
        var empCode = getPar1("empCode");
        var empName = getPar1("empName");
        var postRank = getPar1("postRank");
        $("#PrePosition").val(postName);
        $("#PreDept").val(deptName);
        $("#empCode").val(empCode);
        $("#empName").val(empName);
        if(postRank!="undefined") $("#PrePositionRank").val(postRank);
        getPostIDByPostName(postName);
        $("#PostRank").each(function () {
            $(this).find("option").each(function () {
                if ($(this).text() == postRank) {
                    instance[0].prePostRank = $(this).val(); //调整前职等
                    $("#PostRank").val($(this).val());
                }
            });
        });
        var postType = getPar(location.href, "postType");
        if (postType == "2") {
            instance[0].PostType = 2;
            $("#spanPreDept").text("返聘前部门:");
            $("#spanDept").text("返聘后部门:");
            $("#spanPrePost").text("返聘前岗位:");
            $("#spanPost").text("返聘后岗位:");
            $("#spanPreLevel").text("返聘前职等:");
            $("#spanLevel").text("返聘后职等:");
        }
    });
}

var ValueChanged = function () { //部门发生变化后
    var deptId = $("#DeptId").val();
    getPostions(deptId); //获取该部门下所有岗位
    instance[0].DeptID = deptId; //调整后部门ID
}

var fnCheckData = function () {
    var postType = getPar(location.href, "postType");
    if (postType == "2") {
        if ($("#PostID").val() == "" || $("#PostID").val() == null) {
            return "返聘后岗位不能为空!";
        }
        if ($("#PostRank").val() == "" || $("#PostRank").val() == null) {
            return "返聘后职等不能为空!";
        }
    }
    else {
        if ($("#PostID").val() == "" || $("#PostID").val() == null) {
            return "调整后岗位不能为空!";
        }
        if ($("#PostRank").val() == "" || $("#PostRank").val() == null) {
            return "调整后职等不能为空!";
        }
    }
    if ($("#ValidDate").val() == "") {
        return "生效日期不能为空!";
    }
}


//根据岗位名称获取岗位ID
function getPostIDByPostName(postName) {
    var url = encodeURI("../Extend/AjaxData/jsonlist.aspx?entity=DatPost&condition=PostName='" + postName + "'");
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total == 0) {
            $("#tishixinxi").text("岗位ID获取失败！");
        }
        else {
            $("#tishixinxi").text("");
            for (var o in list.rows) {
                var v = list.rows[o].PostID; 
                if (typeof (v) != "undefined") {
                    instance[0].PrePostID = v; //调整前岗位
                    break;
                }
            }
        }
    });
}

//获取部门下的岗位
function getPostions(deptID) {
    $("#PostID").find('option').remove();
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=DatPost&condition=DeptID='" + deptID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total == 0) {
            $("#tishixinxi").text("该部门无岗位信息，请先维护部门岗位信息！");
        }
        else {
            $("#tishixinxi").text("");
            for (var o in list.rows) {
                var v = list.rows[o].PostID;
                var t = list.rows[o].PostName;
                if (typeof (t) != "undefined") {
                    $("#PostID").append("<option value='" + v + "'>" + t + "</option>");
                }
            }
        }
    });
}